package com.jied.duodian.service.Impl;

import com.jied.duodian.dao.DdLeibieDAO;
import com.jied.duodian.entity.DdLeibie;
import com.jied.duodian.entity.DdLeibieExample;
import com.jied.duodian.service.DdLeibieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Description:
 *
 * @author LiJie
 * @date Created on 2020/10/28
 * WWW https://github.com/j6l
 */
@Service
@Transactional
public class DdLeibieServiceImpl implements DdLeibieService {

    @Autowired
    DdLeibieDAO ddLeibieDAO;

    /**
     * 获取id 0  名字 1  父类别 2
     * 所有子类 3
     *
     * @param lb
     * @return
     */
    @Cacheable(cacheNames = "qt", keyGenerator = "keyGenerator")
    @Override
    public List<DdLeibie> getLeibie(DdLeibie lb, Integer id) {
        DdLeibieExample example = new DdLeibieExample();
        DdLeibieExample.Criteria criteria = example.createCriteria();
        if (id == 0) criteria.andShuxingEqualTo( lb.getId() );
        if (id == 1) criteria.andNameEqualTo( lb.getName() );
        if (id == 2) criteria.andShuxingEqualTo( lb.getShuxing() );
        if (id == 3) criteria.andShuxingNotEqualTo( lb.getShuxing() );
        return ddLeibieDAO.selectByExample( example );
    }

    @Cacheable(cacheNames = "qt", keyGenerator = "keyGenerator")
    @Override
    public List<DdLeibie> getLeibieBYshuxing() {
        DdLeibieExample example = new DdLeibieExample();
        DdLeibieExample.Criteria criteria = example.createCriteria();
        criteria.andShuxingGreaterThan( 0 );
        return ddLeibieDAO.selectByExample( example );
    }

    @Override
    public Integer updataLeibie(DdLeibie list) {
        return ddLeibieDAO.updateByPrimaryKeySelective( list );
    }

    @Override
    public Integer delLeibie(DdLeibie list) {
        return ddLeibieDAO.deleteByPrimaryKey( list.getId() );
    }

    @Override
    public Integer addLeibieList(DdLeibie list) {
        return ddLeibieDAO.insertSelective( list );
    }
}
